<?php

class GroupsController extends AppController {

    var $name = 'Groups';
    var $helpers = array('Html', 'Form');

    function beforeFilter() {
        parent::beforeFilter();
    }

    function backstage_index() {
        $this->layout = 'admin';
        $this->Group->recursive = 0;
        $this->paginate = array(
            'Group' => array('limit' => 10, 'order' => array('Group.group_type DESC'))
        );
        $this->set('groups', $this->paginate());
    }

    function view($id = null) {
        if (!$id) {
            $this->Session->setFlash(__('Invalid Group.', true));
            $this->redirect(array('action' => 'index'));
        }
        $this->set('group', $this->Group->read(null, $id));
    }

    function add() {
        $this->layout = false;
        if (!empty($this->data)) {
            $this->Group->create();
            if ($this->Group->save($this->data)) {
                $this->render('addsuccess');
            } else {
                $this->Session->setFlash(__('The Group could not be saved. Please, try again.', true));
            }
        }
    }

    function edit($id = null) {
        $this->layout = false;
        if (!$id && empty($this->data)) {
            $this->Session->setFlash(__('Invalid Group', true));
            $this->redirect(array('action' => 'index'));
        }
        if (!empty($this->data)) {
            if ($this->Group->save($this->data)) {
                $this->render('editsuccess');
            } else {
                $this->Session->setFlash(__('The Group could not be saved. Please, try again.', true));
            }
        }
        if (empty($this->data)) {
            $this->data = $this->Group->read(null, $id);
        }
    }

    function delete($id = null) {
        if (!$id) {
            $this->Session->setFlash(__('Invalid id for Group', true));
            $this->redirect(array('action' => 'index'));
        }
        if ($this->Group->del($id)) {
            $this->Session->setFlash(__('Group deleted', true));
            $this->redirect(array('action' => 'index'));
        }
    }

}

?>
